package com.yuandian.business.monitor.controller;

import com.yuandian.api.business_monitor.po.LongProcessParams;
import com.yuandian.api.business_monitor.vo.LongProcessDetailVo;
import com.yuandian.bpm.common.core.util.R;
import com.yuandian.business.monitor.service.ILongProcessService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 说明：长流程业务Controller
 * @Author yanjun
 * @Date 2020/9/7 15:07
 */
@RestController
@Api(value = "longProcess", tags = "长流程业务接口")
@RequestMapping("/business/longProcess")
public class LongProcessController {

    @Autowired
    private ILongProcessService longProcessService;

    /**
     * 分页查询长流程概况列表
     * @param params 长流程业务查询对象
     * @return 通用返回对象
     */
    @PostMapping("/overviewList")
	@ApiOperation(value = "分页查询长流程概况列表", notes = "分页查询长流程概况列表")
	@ApiImplicitParams({
			@ApiImplicitParam(name = "systemId",  			value = "业务系统id",  			paramType = "query", required = true,  dataType = "Integer"),
			@ApiImplicitParam(name = "time",  		value = "开始日期",  		paramType = "query", required = false, dataType = "List<Integer>"),
			@ApiImplicitParam(name = "opIdCode", 		value = "操作员",  		paramType = "query", required = false, dataType = "List<Integer>"),
			@ApiImplicitParam(name = "sysProcessId", 			value = "业务流转号",  		paramType = "query", required = false, dataType = "List<Integer>"),
	})
    public R overviewList(@RequestBody LongProcessParams params) {

        return R.ok(longProcessService.pageLongProcessOverview(params));
    }

    /**
     * 查询长流程详情列表
     * @param params 长流程业务查询对象
     * @return 通用返回对象
     */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "isAsc",  		value = "排序规则",  		paramType = "query", required = false, dataType = "List<Integer>"),
			@ApiImplicitParam(name = "orderByColumn", 		value = "排序字段",  		paramType = "query", required = false, dataType = "List<Integer>"),
			@ApiImplicitParam(name = "sysProcessId", 			value = "业务流转号",  		paramType = "query", required = false, dataType = "List<Integer>"),
	})
    @PostMapping("/detailList")
	@ApiOperation(value = "查询长流程详情列表", notes = "查询长流程详情列表")
    public R detailList(@RequestBody LongProcessParams params) {
        List<LongProcessDetailVo> list = longProcessService.queryLongProcessDetail(params);
        return R.ok(list);
    }

    /**
     * 长流程业务导出Excel
     * @param params 长流程业务查询对象
     */
	@ApiImplicitParams({
			@ApiImplicitParam(name = "isAsc",  		value = "排序规则",  		paramType = "query", required = false, dataType = "List<Integer>"),
			@ApiImplicitParam(name = "orderByColumn", 		value = "排序字段",  		paramType = "query", required = false, dataType = "List<Integer>"),
			@ApiImplicitParam(name = "time", 			value = "时间",  		paramType = "query", required = false, dataType = "List<Integer>"),
	})
    @PostMapping("/exportExcel")
	@ApiOperation(value = "长流程业务导出Excel", notes = "长流程业务导出Excel")
    public void exportExcel(@RequestBody LongProcessParams params, HttpServletResponse response) {
        try {
            longProcessService.exportExcel(params, response);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
